﻿using System.Web;
using System.Web.Mvc;
using Utilities;

namespace Home.WebUI.Areas.NewAdmin.Controllers
{
    public class CommonController : Controller
    {
        //
        // GET: /NewAdmin/Common/

        //上传图片------------------------------------
        public JsonResult UploadImg(FormCollection form)
        {
            Response.Charset = "UTF-8";

            // 初始化一大堆变量
            HttpPostedFileBase postFile = Request.Files["upfile"];//单个文件,表单文件域name
            string attachdir = "/Upload/Images/";     // 上传文件保存路径，结尾要带/
            int maxattachsize = 2048;     // 最大上传大小


            bool i = false;
            string filePath = Common.UpLoad(postFile, "img", maxattachsize, attachdir, 1, ref i);
            if (i)
            {
                var data = new { url = filePath, title = Request.Form["pictitle"], state = "SUCCESS" };
                //JsonResult json = new JsonResult { Data = new { url = filePath, title = Request.Form["pictitle"], state = "SUCCESS" } }; 
                return Json(data, JsonRequestBehavior.AllowGet);
                // msg = jsonString("!" + filePath);
            }
            else
            {
                var data = new { url = filePath, title = Request.Form["pictitle"], state = filePath };
                //JsonResult json = new JsonResult { Data = new { url = filePath, title = Request.Form["pictitle"], state = "SUCCESS" } }; 
                return Json(data, JsonRequestBehavior.AllowGet);

            }

        }

    }
}
